$(function() {
	$('#vue_vm_list').hide();
});

function caregiverSalaryMonth_find() {
	if($('#vue_vm_list').length==0) {return;}
	$('#vue_vm_list').hide();
	var year = parseInt($('#year').val());
	var month = parseInt($('#month').val());
	var subjectRoomId = $('#subjectRoom_select').val();
	
	if(!year || year=='') {
		alert('请输入年份');
		return;
	}
	if(!month || month=='') {
		alert('请输入月份');
		return;
	}
	if(!subjectRoomId || subjectRoomId=='') {
		alert('请选择科室');
		return;
	}
	
	find_basic_by_json(path+'/caregiverSalaryMonth/find',
			{year:year, month:month, subjectRoomId:subjectRoomId}, function(response) {	
		$('#vue_vm_list').html(gl_vue_vm_list_html);
		
		new Vue({
			el: '#vue_vm_list',
			data: {
				todos: response.data
			},
			methods: {
				getYearMonthText:function() {
					return year+'年'+month+'月'
				}
			}
		});
		
		$('#vue_vm_list').show();
	});
}

function payOff_Batch() {
	var itemIdStr = '';
	var itemIdArray = [];
	
	$('ul').each(function() {
		if($(this).find('.magic-checkbox').is(':checked')) {
			var itemId = $(this).find('.magic-checkbox').attr('id');
			itemIdStr += (itemIdStr==''? itemId: ','+itemId);
			itemIdArray.push(itemId);
		}
	});
	
	if(itemIdArray.length == 0) {
		alert('请先勾选护理员工资');
		return;
	}
	
	if(confirm('确实要处理勾选的护理员工资吗？')) {
		openWaiting('正在处理工资');
		
		var dataStr = JSON.stringify({ids:itemIdArray});
		
		$.post(path+'/caregiverSalaryMonth/payoff', {data: dataStr}, function(response) {
			closeWaiting();
			
			if(response.code=='200') {
				$('ul').each(function() {
					if($(this).find('.magic-checkbox').is(':checked')) {
						$(this).remove();
					}
				});
				
				alert('工资处理成功');
			}else {
				alert(response.info);
			}
			
			console.log(response);
		});
	}
};